package com.cbd.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cbd.dao.PersonalcarportDao;
import com.cbd.dao.RecordDao;
import com.cbd.dao.RentInfoDao;
import com.cbd.dao.impl.RecordDaoImpl;
import com.cbd.pojo.PageBean;
import com.cbd.pojo.Personalcarport;
import com.cbd.pojo.Record;
import com.cbd.pojo.RentInfo;
import com.cbd.service.PersonalcarportService;
import com.cbd.service.RentInfoService;
@Service
public class PersonalcarportServiceImpl implements PersonalcarportService {
	@Resource(name="personalcarportDaoImpl")
	private PersonalcarportDao pld;
	@Resource(name="recordDaoImpl")
	private RecordDao rd;
	@Resource(name="rentInfoDaoImpl")
	private RentInfoDao rentInfoDao;
	@Override
	public PageBean findAllCarPortByLadyId(int ladyId, PageBean page) {
		// TODO Auto-generated method stub
		int num = pld.findCarPortNum(ladyId);
		page.setCountPage(num%page.getPageSize()==0?(num/page.getPageSize()):(num/page.getPageSize()+1));
		page = pld.findAllPortByLandLadyId(ladyId, page);
		return page;
	}

	@Override
	public void delCarPortById(int id) {
		// TODO Auto-generated method stub
		pld.delCarPortById(id);
	}

	@Override
	public int addPort(Personalcarport personalcarport) {
		// TODO Auto-generated method stub
		return pld.addPort(personalcarport);
	}

	@Override
	public int checkCarportNO(String carportNO) {
		// TODO Auto-generated method stub
		return pld.checkCarportNO(carportNO);
	}

	@Override
	public int checkCarNO(String carNO, String carportAddress) {
		// TODO Auto-generated method stub
		return pld.checkCarNO(carNO, carportAddress);
	}

	@Override
	public List<Personalcarport> getAllCarPort(int ladyID) {
		// TODO Auto-generated method stub
		return pld.getAllCarPort(ladyID);
	}
	
	@Override
	public PageBean findAllPortByLandLadyId(int ladyId, PageBean page) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Personalcarport> findAllUsablePort(int ladyId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Personalcarport> findAllNoPassPort(int ladyId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int findCarPortNum(int ladyId) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void updateCarPortIsRentById(int carPortID) {
		// TODO Auto-generated method stub
		pld.updateCarPortIsRentById(carPortID);
	}

	@Override
	public void checkAllPort() {
		// TODO Auto-generated method stub
		List<RentInfo> list = rentInfoDao.findAllRentInfoByLadyId();
		for (RentInfo r : list) {
			if(new Date().getTime()>r.getEndTime().getTime()){
				pld.updateCarPortIsRentFalseById(r.getPersonalcarport().getCarportID());
				rentInfoDao.updateInfoTypeById(r.getRentInfoID());
			}
		}
				
	}
}
